home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / lib / partman / commit.d / 01unmount_busy next >
Text File  |  2008-10-29  |  2KB  |  108 lines

  1. #! /bin/sh
  2.  
  3. . /lib/partman/lib/base.sh
  4.  
  5. db_get ubiquity/partman-skip-unmount
  6. if [ "$RET" = true ]; then
  7.     exit 0
  8. fi
  9.  
  10. if [ -f /etc/mtab ]; then
  11.     MTAB=/etc/mtab
  12. else
  13.     MTAB=/proc/mounts
  14. fi
  15.  
  16. busy_partitions=
  17.  
  18. for dev in $DEVICES/*; do
  19.     [ -d "$dev" ] || continue
  20.     cd $dev
  21.  
  22.     partitions=
  23.     found_mounted=false
  24.     open_dialog PARTITIONS
  25.     while { read_line num id size type fs path name; [ "$id" ]; }; do
  26.     [ "$fs" != free ] || continue
  27.     partitions="$partitions $id,$path"
  28.     if [ -f "$id/mountpoint" ]; then
  29.         mp="$(cat "$id/mountpoint")"
  30.         case $mp in
  31.         /media/*)
  32.             ;;
  33.         *)
  34.             found_mounted=:
  35.             ;;
  36.         esac
  37.     fi
  38.     done
  39.     close_dialog
  40.  
  41.     if ! $found_mounted; then
  42.     open_dialog IS_CHANGED
  43.     read_line changed
  44.     close_dialog
  45.     [ "$changed" = yes ] || continue
  46.     fi
  47.  
  48.     for part in $partitions; do
  49.     id="${part%,*}"
  50.     path="${part#*,}"
  51.     open_dialog IS_BUSY "$id"
  52.     read_line busy
  53.     close_dialog
  54.     [ "$busy" = yes ] || continue
  55.     busy_partitions="$busy_partitions $path"
  56.     done
  57. done
  58.  
  59. [ "$busy_partitions" ] || exit 0
  60.  
  61. noninteractive=:
  62. while :; do
  63.     failed_mountpoints=
  64.     for part in $busy_partitions; do
  65.     for mp in $(grep "^$part " "$MTAB" | cut -d' ' -f2); do
  66.         # This is impressively horrible, but it's the best way I can
  67.         # come up with to unmangle mtab entries in shell.
  68.         new_mp=
  69.         while [ "$mp" ]; do
  70.         case $mp in
  71.             \\[0-9][0-9][0-9]*)
  72.             octal="$(echo "$mp" | sed 's/^\\\([0-9][0-9][0-9]\).*/\1/')"
  73.             new_mp="$new_mp$(printf "\\$octal")"
  74.             mp="${mp#\\[0-9][0-9][0-9]}"
  75.             ;;
  76.             \\*)
  77.             new_mp="$new_mp\\"
  78.             mp="${mp#\\}"
  79.             ;;
  80.             *\\*)
  81.             new_mp="$new_mp${mp%%\\*}"
  82.             mp="\\${mp#*\\}"
  83.             ;;
  84.             *)
  85.             new_mp="$new_mp$mp"
  86.             mp=
  87.             ;;
  88.         esac
  89.         done
  90.         umount "$new_mp" || failed_mountpoints="${failed_mountpoints:+$failed_mountpoints }$new_mp"
  91.     done
  92.     done
  93.  
  94.     if [ -z "$failed_mountpoints" ]; then
  95.     break
  96.     fi
  97.  
  98.     db_reset ubiquity/partman-failed-unmount
  99.     db_subst ubiquity/partman-failed-unmount MOUNTED "$failed_mountpoints"
  100.     db_input critical ubiquity/partman-failed-unmount || $noninteractive
  101.     db_go || exit 1
  102.     db_get ubiquity/partman-failed-unmount
  103.     [ "$RET" = true ] || exit 1
  104.     noninteractive='exit 1'
  105. done
  106.  
  107. exit 0
  108.